﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;  

namespace ChessEst1
{ 
    //these two classes used by Program.cs simply to prevent cluttering in Program.cs with tasks such as filling the ChessPlayersDict and output to screen
    //after TortoiseSVN installed for source control, 9-26-13
    class HelperClass1
    {


        public List<string> ConsoleOutputStrings = new List<string>();

        public Dictionary<int, ChessPlayer> ChessPlayersDict = new Dictionary<int, ChessPlayer>();

        public HelperClass1() { }


        public void HelperClass1FillDictionary(List<int> myIntRandomList)
        {
            ChessPlayersDict = new Dictionary<int, ChessPlayer>();
            //by convention, the 0th index ID number is the target chessplayer 
            int i = 0;

            foreach (int dL in myIntRandomList)
            {
                ChessPlayer cp = new ChessPlayer(i, dL);
                ChessPlayersDict.Add(i, cp);
                i = i + 1;
            }

        }

        public void AddChessPlayerToDict(int interg, ChessPlayer CP)
        {
            if (ChessPlayersDict == null) return;
            ChessPlayersDict.Add(interg, CP);
        }
    

    }
    class DisplayClass
    {

        public List<string> Display1ListStrings = new List<string>();
        public List<string> Display2ListStrings = new List<string>();
        public bool isVerbose = false;

        public DisplayClass() { }

        public void Display1()
        {
            string m0 = "SWISS CHESS TOURNAMENT WINNER PREDICTION SIMULATOR";
            Console.WriteLine(m0);
            m0 = String.Format("SWISS CHESS TOURNAMENT WINNER PREDICTION SIMULATOR");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = String.Empty;
            Display1ListStrings.Add(m0);
            m0 = "This program estimates the probability of a given chess player";
            Console.WriteLine(m0);
            m0 = String.Format("This program estimates the probability of a given chess player");
            Display1ListStrings.Add(m0);
            m0 = "winning a Swiss-style chess tournament.";
            Console.WriteLine(m0);
            m0 = String.Format("winning a Swiss-style chess tournament.");
            Display1ListStrings.Add(m0);            
            m0 = "The user should be familiar with statistics such as";
            Console.WriteLine(m0);
            m0 = String.Format("The user should be familiar with statistics such as");
            Display1ListStrings.Add(m0); 
            m0 = "the mean and standard deviation.";  
            Console.WriteLine(m0);
            m0 = String.Format("the mean and standard deviation.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The program requires from the user the following inputs: ";
            Console.WriteLine(m0);
            m0 = String.Format("The program requires from the user the following inputs: ");
            Display1ListStrings.Add(m0);
            m0 = "--The mean Elo and the standard deviation";
            Console.WriteLine(m0);
            m0 = String.Format("--The mean Elo and the standard deviation");
            Display1ListStrings.Add(m0);
            m0 = "of all the chess players in the tournament.";
            Console.WriteLine(m0);
            m0 = String.Format("of all the chess players in the tournament.");
            Display1ListStrings.Add(m0);
            m0 = "--The Player Elo = the Elo of the chosen chess player";
            Console.WriteLine(m0);
            m0 = String.Format("--The Player Elo = the Elo of the chosen chess player");
            Display1ListStrings.Add(m0);
            m0 = "under consideration to win the tournament.";
            Console.WriteLine(m0);
            m0 = String.Format("under consideration to win the tournament.");
            Display1ListStrings.Add(m0);
            m0 = "--The total number of chess players in the tournament";
            Console.WriteLine(m0);
            m0 = String.Format("--The total number of chess players in the tournament");
            Display1ListStrings.Add(m0);
            m0 = "--The number of games to be played by each player";
            Console.WriteLine(m0);
            m0 = String.Format("--The number of games to be played by each player");
            Display1ListStrings.Add(m0);
            m0 = "--The number of iterations that the chess simulator will run.";
            Console.WriteLine(m0);
            m0 = String.Format("--The number of iterations that the chess simulator will run.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The program takes from a few seconds to several hours to run,";
            Console.WriteLine(m0);
            m0 = String.Format("The program takes from a few seconds to several hours to run,");
            Display1ListStrings.Add(m0);
            m0 = "depending on the parameters chosen (bigger nos. = longer time).";
            Console.WriteLine(m0);
            m0 = String.Format("depending on the parameters chosen (bigger nos. = longer time).");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The user can abort the program anytime, by closing the window.";
            Console.WriteLine(m0);
            m0 = String.Format("The user can abort the program anytime, by closing the window.");
            Display1ListStrings.Add(m0);
            m0 = "A progress bar shows percent completion.";
            Console.WriteLine(m0);
            m0 = String.Format("A progress bar shows percent completion.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The program outputs its main results to the screen,";
            Console.WriteLine(m0);
            m0 = String.Format("The program outputs its main results to the screen,");
            Display1ListStrings.Add(m0);
            m0 = "and optionally more data to a small text file (usually limited to ~130 kb).";
            Console.WriteLine(m0);
            m0 = String.Format("and optionally more data to a small text file (usually limited to ~130 kB).");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The results tell how often the chosen chess player wins first place,";
            Console.WriteLine(m0);
            m0 = String.Format("The results tell how often the chosen chess player wins first place,");
            Display1ListStrings.Add(m0);
            m0 = "and how the other players fare.";
            Console.WriteLine(m0);
            m0 = String.Format("and how the other players fare.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The program makes no changes to a user's machine, nevertheless,";
            Console.WriteLine(m0);
            m0 = String.Format("The program makes no changes to a user's machine, nevertheless,");
            Display1ListStrings.Add(m0);
            m0 = "the user should take care to download this program from a reputable source,";
            Console.WriteLine(m0);
            m0 = String.Format("the user should take care to download this program from a reputable source,");
            Display1ListStrings.Add(m0);
            m0 = "such as CodePlex.com URL: http://swisschesswinpredict.codeplex.com/";
            Console.WriteLine(m0);
            m0 = String.Format("such as CodePlex.com URL: http://swisschesswinpredict.codeplex.com/");
            Display1ListStrings.Add(m0);
            m0 = "and run it through a virus checker and/or in a sandbox environment.";
            Console.WriteLine(m0);
            m0 = String.Format("and run it through a virus checker and/or in a sandbox environment.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The program is released AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.";
            Console.WriteLine(m0);
            m0 = String.Format("The program is released AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.");
            Display1ListStrings.Add(m0);
            m0 = "(c) 2012, by JayRodrequez.  Freeware.  Written in Visual Studio C#.";
            Console.WriteLine(m0);
            m0 = String.Format("(c) 2012, by JayRodrequez.  Freeware.  Written in Visual Studio C#.");
            Display1ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "HIT ENTER TO CONTINUE. TYPE 'Q' and RETURN TO QUIT.";
            Console.WriteLine(m0);
            m0 = String.Format("HIT ENTER TO CONTINUE. TYPE 'Q' and RETURN TO QUIT.");
            Display1ListStrings.Add(m0);
            m0 = String.Empty;
            Display1ListStrings.Add(m0);
        }

        public void Display2() 
        {
             isVerbose = true; //
            //if user wants more info, assume verbose mode and log all console instructions, including Display1
            foreach (string s in Display1ListStrings)
            {
                Display2ListStrings.Add(s);
            }
            string ContinueYorNString = String.Empty;
            string m0 = "SWISS CHESS TOURNAMENT WINNER PREDICTION PROGRAM DETAILS";            
            Console.WriteLine(m0);
            m0 = String.Format("SWISS CHESS TOURNAMENT WINNER PREDICTION PROGRAM DETAILS");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = String.Empty;
            Display2ListStrings.Add(m0);
            m0 = "The program uses mean and sigma to form a Gaussian distribution of players.";
            Console.WriteLine(m0);
            m0 = String.Format("The program uses mean and sigma to form a Gaussian distribution of players.");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "The players are ranked so the strongest player plays the weakest in round 1,";
            Console.WriteLine(m0);
            m0 = String.Format("The players are ranked so the strongest player plays the weakest in round 1,");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "the second strongest plays the second weakest, and so on.";
            Console.WriteLine(m0);
            m0 = String.Format("the second strongest plays the second weakest, and so on.");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "However, after the first round, players nearest in strength play each other";
            Console.WriteLine(m0);
            m0 = String.Format("However, after the first round, players nearest in strength play each other");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "Tie break is used to sort players from strongest to weakest according to the following:";
            Console.WriteLine(m0);
            m0 = String.Format("Tie break is used to sort players from strongest to weakest according to the following:");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "First, winning points; second, winning points won by a player's opponent (Solkoff tiebreak);";
            Console.WriteLine(m0);
            m0 = String.Format("First, winning points; second, winning points won by a player's opponent (Solkoff tiebreak);");
            Display2ListStrings.Add(m0);
            Console.WriteLine();

            m0 = "and third, initial Elo rating.  This system should give an accurate picture over many iterations.";
            Console.WriteLine(m0);
            m0 = String.Format("and third, initial Elo rating.  This system should give an accurate picture over many iterations.");
            Display2ListStrings.Add(m0);
            Console.WriteLine();


            m0 = "More info? Type Y=Yes, hit enter, or hit ENTER for N=No (Default)";
            Console.WriteLine(m0);
            try
            {
                ContinueYorNString = Console.ReadLine();
            }
            catch (System.IO.IOException ex1)
            {
                Console.WriteLine(ex1.InnerException.Message);
            }
            catch (Exception ex2)
            {
                Console.WriteLine(ex2.InnerException.Message);
            }
            if (ContinueYorNString == "Y" || ContinueYorNString == "y")
            {
               this.Display3();
            }
             
        }

        public void Display3()
        {
            string m0 = "Program output is on the console screen and more info in a text file.";
            Console.WriteLine(m0);
            m0 = String.Format("Program output is on the console screen and more info in a small text file.");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "The text file is limited to usually 130 kb in size, and ~300 kb max.";
            Console.WriteLine(m0);
            m0 = String.Format("The text file is limited to usually 130 kb in size, and ~300 kb max.");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "Output is given as the % wins by: (1) the chosen player (CP), (2) all players within 50 pts of the CP,";
            Console.WriteLine(m0);
            m0 = String.Format("Output is given as the % wins by: (1) the chosen player (CP), (2) all players within 50 pts of the CP,");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "(3) all players having an Elo two sigma or greater from the mean, (4) 1-2 sigma above the mean";
            Console.WriteLine(m0);
            m0 = String.Format("(3) all players having an Elo two sigma or greater from the mean, (4) 1-2 sigma above the mean");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "(5) +/- 1 sigma from the mean, (6) 1-2 sigma below the mean, and, (7) 2 sigma or greater below the mean.";
            Console.WriteLine(m0);
            m0 = String.Format("(5) +/- 1 sigma from the mean, (6) 1-2 sigma below the mean, and, (7) 2 sigma or greater below the mean");
            Display2ListStrings.Add(m0);
            Console.WriteLine();
            m0 = "Finally, the text file logs the first 10 upset wins (2+ sigma below the mean) and the first 1000 wins.";
            Console.WriteLine(m0);
            m0 = String.Format("Finally, the text file logs the first 10 upset wins (2+ sigma below the mean) and the first 1000 wins.");
            Display2ListStrings.Add(m0);
            m0 = String.Empty;
            Display2ListStrings.Add(m0);

            Console.WriteLine();

        }
    }
}

 
